package de.mmis.core.base;

import java.util.Arrays;
import java.util.Vector;

/**
 * Simple structure representing a polygon in 2- or 3-dimensional space
 * @author Marcel Holle
 */
public class Polygon {
	public Vector<Position> points;

	/**
	 * creates new empty Polygon
	 */
	public Polygon() {
		this(new Vector<Position>());
	}
	
	/**
	 * creates new Polygon
	 * @param points of polygon as array of Position
	 */
	public Polygon(Position[] points) {
		this(new Vector<Position>(Arrays.asList(points)));
	}
	
	/**
	 * creates new Polygon
	 * @param points of polygon as list of Position
	 */
	public Polygon(Vector<Position> points) {
		this.points = new Vector<Position>(points);
	}
	
	/**
	 * @param index
	 * @return point of an given index
	 */
	public Position getPoint(int index) {
		return this.points.get(index);
	}
	
	/**
	 * @return all points of the polygon
	 */
	public Vector<Position> getPoints() {
		return this.points;
	}
	
	/**
	 * sets the points of the polygon
	 * @param points
	 */
	public void setPoints(Vector<Position> points) {
		this.points = points;
	}
	
	/**
	 * adds a point to the end of the polygon
	 * @param point
	 */
	public void addPoint(Position point) {
		this.points.add(point);
	}
	
	/**
	 * removes the point at a given index
	 * @param index
	 */
	public void removePoint(int index) {
		this.points.remove(index);
	}
	
	@Override
	public int hashCode() {
		return this.points.hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		return this.points.equals(obj);
	}
	
	@Override
	public String toString() {
		return this.points.toString();
	}
}
